<include file="Public/head" title="实名认证-证件信息"/>
<include file="Public/back_head"/>
<div class="main">
	<if condition="$info.card_number neq null">
	    <div class="Idcard_warp">
	        <div class="Idcard_top clear">
	            身份证号
	            <span>{$info.card_number}</span>
	        </div>
	        <div class="Idcard_con">
	            身份证照片
	        </div>
	        <div class="Idcard_img clear">
	            <div class="bottom_file_l">
	                <div class="file_img" style="background-image:  url({:$info['card_fpic']})"></div>
	            </div>
	            <div class="bottom_file_r">
	                <div class="file_img" style="background-image:  url({:$info['card_bpic']})"></div>
	            </div>
	        </div>
	    </div>
    <else/>
	    <form id="dataForm" onsubmit="return false;">
	        <div class="Idcard_warp">
	            <div class="Idcard_top clear">
	                身份证号
	                <label for="" class="r">
	                    <input type="number" id="sfz" name="card_number" placeholder="请输入身份证号" maxlength="18" dir="rlt" oninput="if(value.length>18)value=value.slice(0,18)" >
	                </label>
	            </div>
	            <div class="Idcard_con">
	                身份证照片
	            </div>
	            <div class="Idcard_img clear" id="list">
	                <div class="bottom_file_l" id="upload_image">
	                    <i class="iconfont icon-plus"></i>
	                    <div class="file_zi">请上传身份证明正面照</div>
	                    <div class="" style="background-image:  url(image/bike_show2.jpg)"></div>
	                </div>
	            </div>
	        </div>
	        <div class="zhuyi">
	            <i class="iconfont icon-zhuyi"></i>请提供二代居民身份证正反面照片，身份证信息无法更改
	        </div>
	        <button class="save_btn" onclick="save()">确定</button>
	    </form>
    </if>
</div>
<script type="text/javascript">
$(function () {
    // $(".file_left").focus(function () {
    //     $(".bottom_file_l .file_img").removeClass("hide");
    // });
    // var i=1;
    // $(".file_right").focus(function () {
    //     i++;
    //     if(i<3){
    //         layer.msg("身份证照片缺少，请添加")
    //     }else{
    //         $(".save_btn").removeAttr("disabled")
    //     }
    // })
})
</script>

<script>
        var is_sub = false;
        function save() {
            if (is_sub) {
                return false;
            } else {
                is_sub = true;
            }
            var jy = $('#sfz').val();
            if(jy.length !=18){
                layer.msg('身份证号不正确'),time(1500);
                return false;
            }

            $.post("{:U('card')}",$('#dataForm').serialize(), function(data) {
                if(data.status == '1'){
                    layer.msg(data.info);
                    setTimeout("location.href='"+data.url+"'",1000);
                }else{
                    layer.msg(data.info);
                }
            });
        }
    </script>

<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
    wx.config({
        debug : false,
        appId : "{$signPackage['appId']}", // 必填，公众号的唯一标识
        timestamp:"{$signPackage['timestamp']}", // 必填生成签名的时间戳
        nonceStr : "{$signPackage['nonceStr']}", // 必填生成签名的随机串
        signature : "{$signPackage['signature']}",// 必填签名，见附录1
        jsApiList : [ 'getLocation', 'checkJsApi', 'chooseImage',
                'uploadImage', 'downloadImage', 'previewImage' ]
    // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
    });
        wx.ready(function() {
                    document.querySelector('#upload_image').onclick = function() {
                        var images = {
                            localId : [],
                            serverId : []
                        };
                        if ($("input[name='localId[]']").length >= 2) {
                            layer.open({
                                content : '仅限2张照片',
                                skin : 'msg',
                                time : 2
                            });
                            return false;
                        }

        wx.chooseImage({
            count : 6 - $("input[name='localId[]']").length, // 默认9
            sizeType : [ 'compressed' ],
            sourceType : [ 'album', 'camera' ],
            success : function(res) {
                var localIds = res.localIds;
                var i = 0, length = localIds.length;
                function upload() {
                    wx.uploadImage({
                    localId : localIds[i].toString(),
                    success : function(res) {
                        var str = '';
                        var localData = '';
                        //判断是否是苹果
                        var ua = window.navigator.userAgent.toLowerCase();
                        var s = ua.match(/IPhone/i);
                        str = '';
                        if(s){
                            wx.getLocalImgData({
                                localId: localIds[i].toString(), // 图片的localID
                                success: function (ress) {                           
                                  localData = ress.localData; //localData是图片的base64数据，可以用img标签显示
                                  str += '<div class="bottom_file_l">';
                                  str += '<div class="upload" ><img style="width:150px; height:70px;" src="'+localData+'"></div>';
                                  str += "<input name='image_name[]' type='hidden' value='" + res.serverId + "' />";
                                  str += '<a href="javascript:;" style="z-index:100;" onclick="$(this).parents(\'.upload\').remove()" >x</a>';
                                  str += '</div>';
                                  $('#list').before(str);
                                }
                              });
                        }else{
                            str += '<div class="bottom_file_l">';
                            str += '<div class="" style="background-image:  url('+localIds[i].toString()+')"></div>';
                            str += "<input name='image_name[]' type='hidden' value='" + res.serverId + "' />";           
                            str += '<a href="javascript:;" style="z-index:100;" onclick="$(this).parents(\'.upload\').remove()" >x</a>';
                            str += '</div>';
                            $('#list').before(str);
                           }
                        i++;
                        if (i < length) {
                            upload();
                        }
                    },
                    fail : function(res) {
                        layer.msg(JSON.stringify(res));
                    }
                });
                }
            upload();
            }
        });
    };
});
</script>
<include file="Public/foot"/>